﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL1;
using dto2; //cần Add reference
using System.Data;
using System.Data.OleDb;
namespace BLL
{
    class DiemthiDAL
    {
        public List<DIEMTHI> GetAll()
        {

            DIEMTHI dt;
            List<DIEMTHI> list = new List<DIEMTHI>();
            DataProvider dataprovider = new DataProvider();
            DataTable datatable = new DataTable();
            datatable = dataprovider.ExecuteSelectQuery("Select * from DIEMTHI", null);
            for (int i = 0; i < datatable.Rows.Count; i++)
            {
                dt = new DIEMTHI();
                dt.Diem = Convert.ToDecimal(datatable.Rows[i]["Diem"]);
               
                list.Add(dt);
            }
            return list;
        }

        public DIEMTHI GetDIEMTHI(byte diem)
        {
            DataProvider dataprovider = new DataProvider();
            OleDbParameter[] parameters = new OleDbParameter[1];
            parameters[0] = new OleDbParameter("@diem", OleDbType.TinyInt);
            parameters[0].Value = diem;
            DataTable datatable = new DataTable();
            datatable = dataprovider.ExecuteSelectQuery("Select * from DIEMTHI where Diem = @diem", parameters);
            DIEMTHI dt = new DIEMTHI();
            if (datatable.Rows.Count != 0)
            {
                dt.Diem = Convert.ToByte(datatable.Rows[0]["Diem"]);
                return dt;
            }
            else
                return null;
        }

        public bool UpdateDIEMTHI(byte diem,  byte diemthicu)
        {
            DataProvider dataprovider = new DataProvider();
            OleDbParameter[] parameters = new OleDbParameter[3];
            parameters[0] = new OleDbParameter("@diem", OleDbType.TinyInt);
            parameters[0].Value = diem;
            parameters[1] = new OleDbParameter("@diemthicu", OleDbType.TinyInt);
            parameters[1].Value = diemthicu;
            return dataprovider.ExecuteNonSelectQuery("update DIEMTHI set Diem =@diem, where Diem = @diemthicu", parameters);
        }
    }
}
